package chexuan.game.service.db;

import java.util.ArrayList;
import java.util.Iterator;

import org.dom4j.Element;

import chexuan.game.bean.serviceParam.DBBean;
import chexuan.game.interfaces.common.InterfaceServiceConfiguration;

public class DBConfiguration implements InterfaceServiceConfiguration {

	private final String configurationTag = "db";

	private final ArrayList<DBBean> dbBeans = new ArrayList<DBBean>();

	public DBConfiguration() {
	}

	@Override
	public String getServiceConfigurationRootElement() {
		return configurationTag;
	}

	public void registerDBBean(DBBean bean) {
		if (null == bean || dbBeans.contains(bean)) {
			return;
		}

		Iterator<DBBean> iterator = dbBeans.iterator();
		while (iterator.hasNext()) {
			DBBean dbBean = iterator.next();
			if (dbBean.getEnumDB() == bean.getEnumDB()) {
				return;
			}
		}

		dbBeans.add(bean);
	}

	@Override
	public void readConfigration(Iterator<Element> serviceRootElement,
			Element parentElement) {
		if (serviceRootElement.hasNext()) {
			Element dbElement = serviceRootElement.next();

			for (DBBean bean : dbBeans) {
				// dbElement.g
			}
		}

		// FIXME
		System.out.println("tangqiao");
	}

	@Override
	public void writeConfigration(Iterator<Element> serviceRootElement,
			Element parentElement) {
		// TODO Auto-generated method stub

	}

}
